
$(function() {
	initPage();
	initButton();
});

// 初始化页面
function initPage() {
	//初始化显得是的茶人茶艺在数据库存的type为2
	$.ajax({
		type : "get",
		url : server_url
				+ 'rest/user/product/getRecord.do?ran=' + Math.random(),
		dataType : 'json',
		async : true,
		data : {
			type : 0,
			userId:localStorage.getItem('userid')
		},
		success : function(result) {
			//console.log(result);
			if (result.retCode == '0000') {
				var str = '';
				var proList = result.data;
				if(proList.length>=1){
					//str += '<div class="recommend-box"><div class="recommend-tit">猜你喜欢</div></div><div class="pro-list-b clear">';
					$.each(proList,function(i,n){
						
						//str +='<div class="fl pro-item-b" id="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.pic+'" alt=""><div class="name-box clear"><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div>';
						//str +='<img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.legalName+'</span><span class="fl color02">'+n.teaIndustry+'</span></div><div class="item-time2 clear"><span class="fl">'+n.teaSex+'/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+n.teaTrip+'</span></div><div class="item-time2 clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>万元</div><p class="fr">'+n.detailAddress+'</p></div></div>';

						var teaIndustryStr = ''
						var teaIndustrys = n.teaIndustry.split(",");
						$.each(teaIndustrys,function(i,n){
							if(n==0){
								teaIndustryStr += '<span class="fl color02">茶艺师</span>';
							}else if(n==1){
								teaIndustryStr += '<span class="fl color03">评茶员（师）</span>';
							}else if(n==2){
								teaIndustryStr += '<span class="fl color02">制茶师</span>';
							}else if(n==3){
								teaIndustryStr += '<span class="fl color03">茶园园艺工</span>';
							}
						});
						var age = n.teaAge;
						var year = n.teaYear;
						var trip;
						if(n.teaTrip=='0'){
							trip = '不出差';
						}else{
							trip = '可出差';
						}
						if(n.cateid == "2"){
							//茶人茶艺
							str +='<div class="skill-list clear teatea" type="'+n.cateid+'" productid="'+n.productid+'"><img src="'+n.productPic.picturepath1+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span>'+teaIndustryStr+'</div><div class="item-time clear"><span class="fl">女/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+trip+'</span></div><div class="item-time clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>元</div><p class="fr">'+n.teaLocation+'</p></div></div></div>';
						}else if(n.cateid == "3"){
							//茶叶频道
							str += '<div class="fl pro-item teatea" productid="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.productPic.picturepath1+'" alt="" /><div class="name-box clear"><span class="fl red-box	">现购中</span><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div></div>';
						}else if(n.cateid == "4"){
							//茶区农产
							str += '<div class="fl pro-item teatea " productid="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.productPic.picturepath1+'" alt="" /><div class="name-box clear"><span class="fl red-box	">现购中</span><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div></div>';
						}else if(n.cateid == "1"){
							//茶旅联盟
							//str += '<div class="skill-list clear" ><div class="fl pro-item" productid="'+n.productid+'"><img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span></div><div class="num-box2 clear"><p class="fl">'+n.teaLocation+'</p></div><div class="club-phone-box"><p class="club-phone">'+n.teaPhone+'</p></div><div class="num-box"><div class="fl"><span>'+n.teaPrice+'</span>元/人</div></div></div></div></div>';
							str += '<div class="skill-list clear teatea" productid="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.productPic.picturepath1+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span></div><div class="num-box2 clear"><p class="fl">'+n.teaLocation+'</p></div><div class="club-phone-box"><p class="club-phone">'+n.teaPhone+'</p></div><div class="num-box"><div class="fl"><span>'+n.teaPrice+'</span>元/人</div></div></div></div>';
						}else if(n.cateid == "6"){
							//茶园茶山
							str +=' <div class="list-item clear teatea" type="'+n.cateid+'" productid="'+n.productid+'"><img src="'+n.productPic.picturepath1+'" alt="" class="fl"><div class="item-r fl"><p class="item-tit">'+n.teaTitle+'</p><div class="item-det clear"><span class="fl color01">'+gandenTypeStr+'</span><span class="fl color03">已认证</span></div><div class="item-time clear"><p class="fl">'+n.teaArea+'亩</p><span class="fr">'+n.limitTime+'年</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>万元</div><p class="fr">'+n.teaLocation+'</p></div></div></div></div>';
						}else if(n.cateid == "7"){
							//茶山资讯
							str +='<div class="inf-list clear teatea" productid="'+n.productid+'" type="'+n.cateid+'"><div class="inf-l fl"><p class="">'+n.teaTitle+'</p><div class="time-box clear"><span class="num-s fl">'+n.teaSellNum+'次</span><span class="time-s fr">'+n.addtime+'</span></div></div><div class="inf-r fr"><img src="'+n.productPic.picturepath1+'" alt=""></div></div>';
						}	
							
							
							
						//str +='<div class="skill-list clear teatea" type="'+n.cateid+'" productid="'+n.productid+'"><img src="'+n.productPic.picturepath1+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span>'+teaIndustryStr+'</div><div class="item-time clear"><span class="fl">女/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+trip+'</span></div><div class="item-time clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>元</div><p class="fr">'+n.teaLocation+'</p></div></div></div>';
					
					});
					
				}
				$('#tea00').html(str);
			} else{
				showErrorMsg(result.data);
			}
		}
	});
}


/**
 * 点击事件
 */
function initButton() {
	$('.nav-box li').on('click', function() {
		var index = $(this).index();
		changePage(index);
		$(this).addClass('nav-sel').siblings().removeClass('nav-sel');
		$('.change-item').eq(index).addClass('dis-block').siblings().removeClass('dis-block');
	})	
	
	$("body").on('click','.teatea',function(){
		var param = {};
		param.productId = $(this).attr('productid');
		param.type = $(this).attr('type');
		//跳转
		localStorage.setItem('param',JSON.stringify(param));
		window.location=server_url+"proDetail.do";
	});
	
	$("#deleteRecord").on('click',function(){
		$.ajax({
			type : "get",
			url : server_url
					+ '/rest/user/product/deleteRecord.do?ran=' + Math.random(),
			dataType : 'json',
			async : true,
			data : {
				userId:localStorage.getItem('userid')
			},
			success : function(result) {
				//alert(index);
				//console.log(result);
				if (result.retCode == '0000') {
					window.location.reload();
				}
			}	
		});	
	});
}

function changePage(index) {
	//初始化显得是的茶人茶艺在数据库存的type为2
	$.ajax({
		type : "get",
		url : server_url
				+ 'rest/tea/product/getRecord.do?ran=' + Math.random(),
		dataType : 'json',
		async : true,
		data : {
			type : index,
			userId:localStorage.getItem('userid')
		},
		success : function(result) {
			//alert(index);
			//console.log(result);
			if (result.retCode == '0000') {
				var str = '';
				var proList = result.data;
				if(proList.length>=1){
					//str += '<div class="recommend-box"><div class="recommend-tit">猜你喜欢</div></div><div class="pro-list-b clear">';
					$.each(proList,function(i,n){
						
						//str +='<div class="fl pro-item-b" id="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.pic+'" alt=""><div class="name-box clear"><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div>';
						//str +='<img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.legalName+'</span><span class="fl color02">'+n.teaIndustry+'</span></div><div class="item-time2 clear"><span class="fl">'+n.teaSex+'/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+n.teaTrip+'</span></div><div class="item-time2 clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>万元</div><p class="fr">'+n.detailAddress+'</p></div></div>';

						var teaIndustryStr = ''
						if(n.teaIndustry != null && n.teaIndustry.length >0){
							var teaIndustrys = n.teaIndustry.split(",");
							$.each(teaIndustrys,function(i,n){
								if(n==0){
									teaIndustryStr += '<span class="fl color02">茶艺师</span>';
								}else if(n==1){
									teaIndustryStr += '<span class="fl color03">评茶员（师）</span>';
								}else if(n==2){
									teaIndustryStr += '<span class="fl color02">制茶师</span>';
								}else if(n==3){
									teaIndustryStr += '<span class="fl color03">茶园园艺工</span>';
								}
							});
						}
						var age = n.teaAge;
						var year = n.teaYear;
						var trip;
						if(n.teaTrip=='0'){
							trip = '不出差';
						}else{
							trip = '可出差';
						}
						var gandenTypeStr = '';
						if(n.gandenType==0){
							gandenTypeStr = "国家生态林";
						}else if(n.gandenType==1){
							gandenTypeStr = "成型茶园";
						}else if(n.gandenType==2){
							gandenTypeStr = "荒山茶林";
						}
						
						if(index == 0){
							//茶人茶艺
							str +='<div class="skill-list clear teatea" type="'+n.cateid+'" productid="'+n.productid+'"><img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span>'+teaIndustryStr+'</div><div class="item-time clear"><span class="fl">女/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+trip+'</span></div><div class="item-time clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>元</div><p class="fr">'+n.teaLocation+'</p></div></div></div>';
						}else if(index == 1){
							//茶叶频道
							str += '<div class="fl pro-item teatea" productid="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.pic+'" alt="" /><div class="name-box clear"><span class="fl red-box	">现购中</span><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div></div>';
						}else if(index == 2){
							//茶区农产
							str += '<div class="fl pro-item teatea " productid="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.pic+'" alt="" /><div class="name-box clear"><span class="fl red-box	">现购中</span><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div></div>';
						}else if(index == 3){
							//茶旅联盟
							//str += '<div class="skill-list clear" ><div class="fl pro-item" productid="'+n.productid+'"><img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span></div><div class="num-box2 clear"><p class="fl">'+n.teaLocation+'</p></div><div class="club-phone-box"><p class="club-phone">'+n.teaPhone+'</p></div><div class="num-box"><div class="fl"><span>'+n.teaPrice+'</span>元/人</div></div></div></div></div>';
							str += '<div class="skill-list clear teatea" productid="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span></div><div class="num-box2 clear"><p class="fl">'+n.teaLocation+'</p></div><div class="club-phone-box"><p class="club-phone">'+n.teaPhone+'</p></div><div class="num-box"><div class="fl"><span>'+n.teaPrice+'</span>元/人</div></div></div></div>';
						}else if(index == 4){
							//茶园茶山
							str +=' <div class="list-item clear teatea" type="'+n.cateid+'" productid="'+n.productid+'"><img src="'+n.pic+'" alt="" class="fl"><div class="item-r fl"><p class="item-tit">'+n.teaTitle+'</p><div class="item-det clear"><span class="fl color01">'+gandenTypeStr+'</span><span class="fl color03">已认证</span></div><div class="item-time clear"><p class="fl">'+n.teaArea+'亩</p><span class="fr">'+n.limitTime+'年</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>万元</div><p class="fr">'+n.teaLocation+'</p></div></div></div></div>';
						}else if(index == 5){
							//茶山资讯
							str +='<div class="inf-list clear teatea" productid="'+n.productid+'" type="'+n.cateid+'"><div class="inf-l fl"><p class="">'+n.teaTitle+'</p><div class="time-box clear"><span class="num-s fl">'+n.teaSellNum+'次</span><span class="time-s fr">'+n.addtime+'</span></div></div><div class="inf-r fr"><img src="'+n.pic+'" alt=""></div></div>';
						}
					});
					if(index == 0){
						$('#tea00').html(str);
					}else if(index == 1){
						$('#tea01').html(str);
					}else if(index == 2){
						$('#tea02').html(str);
					}else if(index == 3){
						$('#tea03').html(str);
					}else if(index == 4){
						$('#tea04').html(str);
					}else if(index == 5){
						$('#tea05').html(str);
					}
					
				}
			} else{
				showErrorMsg(result.data);
			}
		}
	});
}
